// /*
//  * @Author: WanYiMing
//  * @Date:2024-05-24-15:46
//  * @Description:
//  */

using Code.DataManager.Model;
using Code.GameLogic.BaseClass.Model;
using Code.GameLogic.Map;

namespace Code.DataManager.Converter
{
    public class MapConvertImpl:ISettingConvert<MapBo,MapJsonBo>
    {
        public MapBo ConvertToBo(MapJsonBo monsterJsonBo)
        {
            MapBo mapBo = new MapBo(new BaseDescription("Map", "标准"));
            mapBo.MapLevel = 1;
            mapBo.MapSize = 50;
            mapBo.BlockMatrix=GetBlockMatrix();
            
            return mapBo;
        }

        public MapBo ConvertToBo(MapJsonBo monsterJsonBo, MapBo result)
        {
            throw new System.NotImplementedException();
        }

        private BlockBo[,] GetBlockMatrix()
        {
            BlockBo[,] blockBos = new BlockBo[50,50];
            MapJsonBo mapJsonBoForJson = DataForJson.GetBlockJsonBoForJson<MapJsonBo>("\\地图.json");
            return ToBlockMatrix(blockBos,mapJsonBoForJson);
        }

        private BlockBo[,] ToBlockMatrix(BlockBo[,] blockBos, MapJsonBo mapJsonBoForJson)
        {
            var blocks = mapJsonBoForJson.blocks;
            foreach (MapJsonBo.Block block in blocks)
            {
                var blockBo = ConvertToBlockBo(block);
                blockBos[block.x,block.y] = blockBo;
            }
            return blockBos;
        }

        private BlockBo ConvertToBlockBo(MapJsonBo.Block block)
        {
            BlockBo blockBo = new BlockBo();
            //0-我方空地	1-路径	2-敌方空地 
            blockBo.Type = block.type;
            blockBo.X = block.x;
            blockBo.Y = block.y;
            blockBo.WatPointOrder = block.watPointOrder;//路点
            blockBo.NextWatPointOrder = block.nextWatPointOrder;//路点指向
            blockBo.MonsterFlashPoint = block.flashPoint;//刷怪点
            return blockBo;
        }
    }
}